/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uit.ieproject.utilites;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author RedDevils
 */
public class TextFilter extends FileFilter {

    private String generalType;

    public TextFilter(String generalType) {
        this.generalType = generalType;
    }

    //accept txt file
    @Override
    public boolean accept(File f) throws UnsupportedOperationException {
        if (f.isDirectory()) {
            return true;
        }

        String extension = FileUtil.getExtension(f);
        if (extension != null) {
            if (generalType.equals("txt")) {
                if (extension.equals("txt")) {
                    return true;
                } else {
                    return false;
                }
            }
            if (generalType.equals("img")) {
                if (extension.equals("png") || extension.equals("jpg")) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return false;
    }

    //description of this filter
    @Override
    public String getDescription() throws UnsupportedOperationException {
        if (generalType.equals("txt")) {
            return "Just Txt";
        }
        if(generalType.equals("img")){
            return ".png | .jpg";
        }
        return ".*";
    }
}
